package com.pe.pgn.clubpgn.dao.impl;

import java.util.List;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.pe.pgn.clubpgn.common.CLPConstantes;
import com.pe.pgn.clubpgn.dao.LineaCreditoDao;
import com.pe.pgn.clubpgn.dao.hibernate.GenericDaoHibernate;
import com.pe.pgn.clubpgn.domain.ClpdLineaCredito;

@Repository("lineaCreditoDao")
public class LineaCreditoDaoImpl extends GenericDaoHibernate<ClpdLineaCredito, Long> 
		implements LineaCreditoDao
	{

	private JdbcTemplate jdbcTemplate;
	
	public LineaCreditoDaoImpl(){
		super(ClpdLineaCredito.class);
	}
	
	public ClpdLineaCredito obtenerLineaCredito(Long coClienteEmpresa) {
		StringBuffer query = new StringBuffer();
		query.append(" select ");
		query.append(" 	 id  as id ,");
		query.append(" 	 co_cliente_empresa  as coClienteEmpresa ,");
		query.append(" 	 va_linea_credito  as vaLineaCredito ,");
		query.append(" 	 va_saldo_credito  as vaSaldoLineaCredito ,");
		query.append(" 	 da_fecha_inicio_contrato  as daFechaInicioContrato ,");
		query.append(" 	 da_fecha_fin_contrato  as daFechaFinContrato ,");
		query.append(" 	 da_fecha_operacion  as daOperacion ,");
		query.append(" 	 co_tipo_linea_creditop  as coTipoLineaCredito ,");
		query.append(" 	 st_linea_credito  as stLineaCredito ");
		query.append(" from clpd_linea_credito ");		query.append(" where 1 = 1 and ");
		query.append(" st_linea_credito = '").append(CLPConstantes.ST_VERDADERO).append("'");		
		query.append(" and coClienteEmpresa = ").append(coClienteEmpresa);
		
		System.out.println(query.toString());
		List list = findListOfBeans(query.toString(), null, ClpdLineaCredito.class);
		if(!list.isEmpty()){
			return (ClpdLineaCredito)list.get(0);
		}
		return null;
	}
	
	

}
